package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.Put;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author 苏靓仔
 * @version 1.0
 */
@RestController("adminShopController")
@Api(tags = "店铺相关接口")
@Slf4j
@RequestMapping("/admin/shop")
public class ShopController {

	// private final static  String SHOPSTATUSKEY;

	@Autowired
	private RedisTemplate redisTemplate;

	/**
	 * 设置营业状态
	 * @param status
	 * @return
	 */
	@PutMapping("/{status}")
	@ApiOperation("设置营业状态")
	public Result updateShopStatus(@PathVariable Integer status){
		log.info("营业状态：{}",status == 1 ? "营业中":"打烊中");
		redisTemplate.opsForValue().set("SHOPSTATUSKEY",status);
		return Result.success();
	}


	/**
	 * 获取营业状态
	 * @return
	 */
	@GetMapping("/status")
	@ApiOperation("获取营业状态")
	public Result getShopStatus(){
		Integer value = (Integer) redisTemplate.opsForValue().get("SHOPSTATUSKEY");
		return Result.success(value);
	}
}
